﻿using System.Windows.Input;
using VisualWip.Core;
using VisualWip.PresentationModel;
using VisualWip.TFS2010Common;
using WorkItem = Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem;

namespace VisualWip.TFS2010Providers
{
    public class TfsOpenWorkItemBehaivour : ICommandWorkItemBehavior, IOpenWorkItemBehavior
    {
        private readonly TfsConnection _connection;
        private readonly ICommand _openCommand;
        private readonly int _workItemId;

        public TfsOpenWorkItemBehaivour(TfsConnection connection, int workItemId)
        {
            _connection = connection;
            _workItemId = workItemId;
            _openCommand = new RelayCommand(param => OpenWorkItem());
        }

        #region ICommandWorkItemBehavior Members

        public ICommand GetCommand()
        {
            return _openCommand;
        }

        #endregion

        public void OpenWorkItem()
        {
            WorkItem wi = _connection.WorkItemStore.GetWorkItem(_workItemId);
            var form = new WorkItemEditor();
            form.SetWorkItem(wi);
            form.Show();
        }
    }
}